package cn.edu.lingnan.springbootlingnanblog.controller.admin;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import cn.edu.lingnan.springbootlingnanblog.entity.Blogger;
import cn.edu.lingnan.springbootlingnanblog.utils.ResponseUtil;
import org.springframework.boot.configurationprocessor.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
//import net.sf.json.JSONObject;
import cn.edu.lingnan.springbootlingnanblog.service.BloggerService;
//import cn.edu.lingnan.springbootlingnanblog.util.DateUtil;
//import cn.edu.lingnan.springbootlingnanblog.util.ResponseUtil;
//

//import java.io.File;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;

@Controller
@RequestMapping("/admin/blogger")
public class BloggerAdminController {

    @Resource
    private BloggerService bloggerService;

//    @RequestMapping("/find")
//    public String find(HttpServletResponse response, int id)throws Exception{
//        Blogger blogger=bloggerService.queryById(id);
//        JSONObject jsonObject=JSONObject.fromObject(blogger);
//        ResponseUtil.write(response, jsonObject);
//        return null;
//    }


    @RequestMapping("/modifyPassword")
    public String modifyPassword(String newPassword, int id, HttpServletResponse response)throws Exception{
        Blogger blogger=new Blogger();
        blogger.setPassword(newPassword);
        blogger.setId(id);
        System.out.println(blogger.getPassword());
        System.out.println(blogger.getId());
//		blogger.setPassword(CryptographyUtil.md5(newPassword, "programmer.ischoolbar.com"));
        boolean resultTotal=bloggerService.update(blogger);
        JSONObject result=new JSONObject();
        if(resultTotal){
            result.put("success", true);
        }else{
            result.put("success", false);
        }
        ResponseUtil.write(response, result);
        return null;
    }

    @RequestMapping("/logout")
    public String  logout()throws Exception{
        return "login";
    }
    @RequestMapping("/indexout")
    public String  indexout()throws Exception{
        return "login";
    }
}
